package com.example.leetdemo.finash;

import java.util.Arrays;

public class Solution1984 {

    public int minimumDifference(int[] nums, int k) {
        Arrays.sort(nums);
        int result = 100010;
        for (int i = 0; i < nums.length - k; i++) {
            result = Math.min(nums[i + k - 1] - nums[i], result);
        }
        return result;
    }

    public static void main(String[] args) {
        Solution1984 solution1984 = new Solution1984();
        System.err.println(solution1984.minimumDifference(new int[] {1,4,8,7,10}, 2));
    }

}
